﻿#include "EquationSolver.h"

using namespace std;
double l = 89, h = 49,beta1 = 11.5 / 180 * M_PI, D1 = 55, D2 = 30;
double trans = M_PI / 180;
double trans2 = 180 / M_PI;
double A = l * sin(beta1), B = l * cos(beta1), C1 = (h + 0.5 * D1) * sin(beta1) - 0.5 * D1 * tan(beta1), C2 = (h + 0.5 * D2) * sin(beta1) - 0.5 * D2 * tan(beta1);
double E1 = (h + 0.5 * D1) * cos(beta1) - 0.5 * D1, E2 = (h + 0.5 * D2) * cos(beta1) - 0.5 * D2;

class F1 : public Function
{
public:
    double operator()(double x) {
        return A * sin(x) * cos(x) + B * pow(sin(x), 2) - C1 * cos(x) - E1 * sin(x);
    }
    double diff(double x) {
        return A * (pow(cos(x), 2) - pow(sin(x), 2)) + 2 * B * sin(x) * cos(x) + C1 * sin(x) - E1 * cos(x);
    }
};

class F2 : public Function
{
public:
    double operator()(double x) {
        return A * sin(x) * cos(x) + B * pow(sin(x), 2) - C2 * cos(x) - E2 * sin(x);
    }
    double diff(double x) {
        return A * (pow(cos(x), 2) - pow(sin(x), 2)) + 2 * B * sin(x) * cos(x) + C2 * sin(x) - E2 * cos(x);
    }
};


int main() {
    cout << "----------------TestF:------------------" << endl;
    F1 func1;
    NewtonSolver n1(33 * trans, eps, 50, func1);
    cout << "------(a)----- " << endl;
    cout << "   root = " << n1.solve() / M_PI * 180 << "     f(root)=" << func1(n1.solve()) << endl << endl;



    F2 func2;
    NewtonSolver n2(33 * trans, eps, 50, func2);
    cout << "------(b)------ " << endl;
    cout << "    root = " << n2.solve() * trans2 << "     f(root)=" << func2(n2.solve()) << endl << endl;



    SecantSolver s1(32 * trans, 34 * trans, eps, 20, func1);
    SecantSolver s2(140 * trans, 160 * trans, eps, 20, func1);
    cout << "------(c)------ " << endl;
    cout << "root1 = " << s1.solve() * trans2 << "    f(root1)=" << func1(s1.solve()) << endl;
    cout << "root2 = " << s2.solve() * trans2 << "    f(root2)=" << func1(s2.solve()) << endl;
    return 0;
}